/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Files;

/**
 *
 * @author Huchnet
 */
public class Estructura {
        String type;
        StringBuffer aBuffer =null;
        String aSource;
        String aBuffer2[];
        int index=0;
        public Estructura(){
            aBuffer = new StringBuffer();
            aBuffer2 = new String[1000];

        }
        public void addStream(String aStream){
            aStream.replaceAll("\n", "");
            aStream.replaceAll("\t", "");

            String []pice=aStream.split(" ");

            for(int i=0;i<pice.length;i++){
                
                if(!pice[i].equalsIgnoreCase("") && !pice[i].equalsIgnoreCase("\n") && !pice[i].equalsIgnoreCase("\t") && !pice[i].equalsIgnoreCase("\\")){
                    aBuffer2[index]=replaceBadCharacter(pice[i]);
                    index++;
                }
                
            }
            aBuffer.append(aStream);

        }
        public StringBuffer getBuffer(){
            return aBuffer;
        }
        String replaceBadCharacter(String aStream){
            String newStream="";
            for(int i=0;i<aStream.length();i++){
                if((int)aStream.charAt(i)==9 | (int)aStream.charAt(i)==10){
                    
                }else{
                    newStream=newStream+aStream.charAt(i);
                }
            }
            return newStream;
        }
        public void mount(){
            System.out.println(aBuffer.substring(aBuffer.indexOf("MSNMS"),150));
            
        }
        public String getChat(){
            int position=0;
            int aux;
            System.out.println("Length: "+aBuffer.length());
            for(int i=0;i<aBuffer.length();i++){
                aux=aBuffer.indexOf("\\r\\n",i);
                if(aux!=-1){
                    position=aux;
                }
                
                if(position+1==i){
                   return null;
                }
                if(aux==-1){
                    return aBuffer.substring(position, aBuffer.length());
                }
                i=position+1;
                
                
            }
            System.out.println("Last Position: "+aBuffer.substring(position, position+20));
            return aBuffer.substring(aBuffer.indexOf("\\r\\n"),aBuffer.indexOf("\\r\\n")+20);
        }
        public void printBuffer(){
            int i=0;
            while(aBuffer2[i]!=null){
                System.out.println(aBuffer2[i]);
                i++;
            }
            
        }

}
